from datetime import timedelta

import logging
from redis import StrictRedis


# 创建配置信息类
class Config(object):
    # 设置密钥
    SECRET_KEY = "HAHAHADSF"
    # 开启调试模式
    DEBUG = True
    # 配置数据库连接信息
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@localhost:3306/information17"
    # 配置数据库追踪信息
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 当会话结束的时候，数据库自动提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # 配置redis主机地址
    REDIS_HOST = "127.0.0.1"
    # 配置redis端口号
    REDIS_PORT = 6379

    # 配置session
    SESSION_TYPE = 'redis'  # 指定session存储类型
    SESSION_USE_SIGNER = True  # 设置签名存储
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 指定session存储对象
    SESSION_PERMANENT = False  # 设置session需要过期
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)  # 设置session过期时间

    # 设置日志级别
    LEVEL = logging.DEBUG


# 开发阶段配置
class DevelopConfig(Config):
    pass


# 生产（线上）阶段配置
class ProductConfig(Config):
    DEBUG = False
    LEVEL = logging.ERROR


# 测试阶段配置
class TestConfig(Config):
    TESTING = True


config_dict = {
    "develop":DevelopConfig,
    "product":ProductConfig,
    "test":TestConfig
}
